package com.pinyoumei.app.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.pinyoumei.app.R;
import com.bumptech.glide.Glide;


/**
 * 分享的Dialog
 */
public class ShareWxDialog extends Dialog implements View.OnClickListener {
    private Context context;
    private String url;


    public ShareWxDialog(Context context, String url){
        super(context, R.style.dialogStyle);
        this.context = context;
        this.url = url;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();//获取一个窗口
        window.setGravity(Gravity.BOTTOM);//设置窗口的位置
        window.setWindowAnimations(R.style.bottom_menu_animation);//设置窗口进入时的动画特效
        WindowManager.LayoutParams layoutParams = window.getAttributes();//获取窗口的属性赋值给layoutParams
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(layoutParams);//设置窗口的属性
        setCanceledOnTouchOutside(true);
        setContentView(R.layout.dialog_share_wx);
        ImageView dialog_iv = findViewById(R.id.dialog_iv);
        LinearLayout source_download = findViewById(R.id.source_download);
        source_download.setOnClickListener(this);

        LinearLayout source_wechat = findViewById(R.id.source_wechat);
        source_wechat.setOnClickListener(this);

        LinearLayout source_friend_circle = findViewById(R.id.source_friend_circle);
        source_friend_circle.setOnClickListener(this);


        Glide.with(context).load(url).into(dialog_iv);


    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.source_download:
                listener.onClick(v);
                dismiss();
                break;
            case R.id.source_wechat:
                listener.onClick(v);
                dismiss();
                break;
            case R.id.source_friend_circle:
                listener.onClick(v);
                dismiss();
                break;
        }
    }
    private OnClickListener listener;
    public interface OnClickListener{
        void onClick(View view);
    }
    public void setOnClickListener(OnClickListener listener){
        this.listener = listener;
    }
    @Override
    public void show() {
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity= Gravity.BOTTOM;
        layoutParams.width= WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height= WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);

    }
}
